package com.twu.biblioteca;

public class MenuOption {

    private final String letter;
    private final String name;
    private final String[] inputs;
    private final Command command;
    private boolean authOnly;
    private boolean noAuthOnly;

    public MenuOption(String letter, String name, Command command) {
        this.letter = letter;
        this.name = name;
        this.command = command;
        this.inputs = null;
        this.authOnly = false;
        this.noAuthOnly = false;
    }

    public MenuOption(String letter, String name, Command command, String... inputs) {
        this.letter = letter;
        this.name = name;
        this.command = command;
        this.inputs = inputs;
        this.authOnly = false;
        this.noAuthOnly = false;
    }

    public String getLetter() {
        return letter;
    }

    public String getName() {
        return name;
    }

    public String[] getInputs() {
        return inputs;
    }

    @Override
    public boolean equals(Object other) {

        if (!(other instanceof MenuOption)) {
            return false;
        }

        MenuOption otherMenuOption = (MenuOption) other;
        return letter.equals(otherMenuOption.letter) &&
               name.equals(otherMenuOption.name) &&
               command.getClass().equals(otherMenuOption.command.getClass());
    }

    @Override
    public int hashCode() {
        int result = letter.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + (inputs != null ? inputs.hashCode() : 0);
        result = 31 * result + command.hashCode();
        return result;
    }

    public String callCommand(Object[] arguments) throws ExitException {
        return command.call(arguments);
    }

    public void makeAuthOnly() {
        this.authOnly = true;
    }

    public boolean isAuthOnly() {
        return authOnly;
    }

    public boolean isNoAuthOnly() {
        return noAuthOnly;
    }

    public void makeNoAuthOnly() {
        this.noAuthOnly = true;
    }
}
